package com.tanhua.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.server.mapper.BlackListMapper;
import com.tanhua.server.pojo.BlackList;
import com.tanhua.server.service.BlackListService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 西楚霸王
 * @date 2020/12/2 11:22
 */
@Service
public class BlackListServiceImpl implements BlackListService {
    @Autowired
    private BlackListMapper blackListMapper;

    @Override
    public IPage<BlackList> queryPageList(Long userId,Integer page,Integer pageSize){
        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        //排序，根据创建时间倒序排序
        queryWrapper.orderByDesc("created");

        //分页的参数
        Page<BlackList> pager = new Page<>(page, pageSize);

        return this.blackListMapper.selectPage(pager,queryWrapper);

    }

    @Override
    public Boolean delBlacklist(Long id, Long userId) {
        QueryWrapper<BlackList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        queryWrapper.eq("black_user_id",userId);
        return this.blackListMapper.delete(queryWrapper) > 0;
    }


}
